import React from 'react';
import {BrowserRouter as Router,Routes,Route,Navigate} from 'react-router-dom';
import Nav from '../pages/Nav';
import routerConfig from './routerConfig';

function Myrouter() {
  return (
    <div>
      <Router>
        <Routes>
            {routerConfig.map(({path,Element,redirect})=>{
                return(
                    <Route 
                      path={path}
                      element={Element?(<Element/>):redirect?(<Navigate to={redirect}/>):(<></>)}
                      key={path}
                    />
                )
            })}
            <Route path='*' element={<Nav/>}/>
        </Routes>
      </Router>
    </div>
  );
}

export default Myrouter;
